package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DishMapper {
    /**
     * 添加菜品和对应的口味数据
     * @param dish
     */
    @AutoFill(value = OperationType.INSERT)
    void insert(Dish dish);

    /**
     * 菜品分页查询
     * @param dishPageQueryDTO
     * @return
     */
    Page<DishVO> pageQuery(DishPageQueryDTO dishPageQueryDTO);

    /**
     * 菜品批量删除
     * @param ids
     */
    void deleteBatch(List<Long> ids);

    /**
     * 根据id查询信息
     * @param id
     * @return
     */
    Dish getById(Long id);

    /**
     * 修改菜品信息及口味
     * 起售 停售
     * @param dish
     */
    @AutoFill(value = OperationType.UPDATE)
    void update(Dish dish);

    /**
     * 根据分类查询菜品
     * @param dish
     * @return
     */
    List<Dish> getBycategoryId(Dish dish);

    /**
     * 根据套餐id查询菜品启售、停售状态
     * @param setmealId
     * @return
     */
    @Select("select status from dish " +
            " where id in (select dish_id from setmeal_dish " +
            "   where setmeal_id = #{setmealId})")
    List<Integer> getStatusBySetmealId(Long setmealId);

    @Select("select count(*) from dish where status = #{status}")
    Integer getCount(Integer status);
}
